// TODO 二分查找法 ，先排序，每次从中间开始找，如果目标值比中间值小，则再左侧的中间值和目标值比较，以此类推
function BinarySearch(arr, target) {
	if (arr.length <= 1) return -1
	//
	let lowIndex = 0
	//
	let highIndex = arr.length - 1
	while (lowIndex <= highIndex) {
		//
		const midIndex = Math.floor((lowIndex + highIndex) / 2)
		if (target < arr[midIndex]) {
			highIndex = midIndex - 1
		} else if (target > arr[midIndex]) {
			lowIndex = midIndex + 1
		} else {
			return midIndex
		}
	}
	return -1
}
console.log(BinarySearch([1, 2, 3, 4, 5], 9))
